#pragma once 
#include <iostream>
#include <pthread.h>
#include <unistd.h>

class My_mutex{
  public:
    My_mutex()
    {
      pthread_mutex_init(&_mutex,NULL);
    }

    void my_lock()
    {
      pthread_mutex_lock(&_mutex);
    }
    void my_unlock()
    {
      pthread_mutex_unlock(&_mutex);
    }

    ~My_mutex()
    {
      pthread_mutex_destroy(&_mutex);
    }

  private:
    pthread_mutex_t _mutex;
};

class Mutex_Guard{
  public:
    Mutex_Guard(My_mutex *mutex)
      :_mutex(mutex)
    {
      _mutex->my_lock();
    }

    ~Mutex_Guard()
    {
      _mutex->my_unlock();
    }
  private:
    My_mutex *_mutex;
};
